package com.quick.calcu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quick.calcu.entity.Student;
import com.quick.calcu.mapper.StudentMapper;
import com.quick.calcu.service.StudentService;
import jakarta.transaction.Transactional;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Transactional
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public List<Student> getStudentsByClassId(Long classId) {
        LambdaQueryWrapper<Student> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Student::getClassId, classId);
        return list(wrapper);
    }

    @Override
    public Student getByUserId(Long userId) {
        LambdaQueryWrapper<Student> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Student::getUserId, userId);
        return getOne(wrapper);
    }

    @Override
    public long getUserIdByStudentId(Long studentId) {
        Student student = getById(studentId);
        return student.getUserId();
    }
}